using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace TMS.Api.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class GetOpenIdController : ControllerBase
    {


        [HttpGet("/GetId/{js_code}")]

        public object GetId(string js_code)
        {
            string url = "https://api.weixin.qq.com/sns/jscode2session?appid=wx32d159b921f0bc40&secret=0efb82c6a766d4227cc53cd86ec16833&js_code=" + js_code + "&grant_type=authorization_code";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";
            request.ContentType = "text/html;charset=UTF-8";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            return retString;
        }
    }
}
